package org.gpp.proj1.test;

import org.gpp.proj1.camera.CameraDirector;
import org.gpp.proj1.camera.action.LookAtPointAction;
import org.gpp.proj1.camera.action.MoveToPointAction;
import org.gpp.proj1.camera.action.SetFocusAction;
import org.gpp.proj1.util.test.JMETestDisplayManager;

import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.scene.CameraNode;
import com.jme.scene.Node;
import com.jme.system.DisplaySystem;
import com.jme.util.LoggingSystem;

/**
 * 
 * Why we must prgram in english?
 * Facade for easyaccept tests
 * @author Pablo Diego
 *
 */
public class CameraFacade {

	private CameraDirector director;
	
	public CameraFacade(){
		// Disabling logging
		LoggingSystem.getLoggingSystem().loggerOn( false );
		
		JMETestDisplayManager.initJME();
	}
	
	public void load(){
		
		Camera cam = DisplaySystem.getDisplaySystem().getRenderer().createCamera( 0, 0 );		
		CameraNode node = new CameraNode( "CamNode", cam );
		this.director = new CameraDirector(node);
	}
	
	public void lookAtPointAction(float x, float y, float z, float duration){
		
		LookAtPointAction action = new LookAtPointAction(this.director.getCamera(), new Vector3f(x,y,z), duration);
		this.director.queueAction(action);
		this.director.updateCamera(0.0f);
	}
	
	public void moveToPointAction(float x, float y, float z, float duration){
		
		MoveToPointAction action = new MoveToPointAction(this.director.getCamera(), new Vector3f(x,y,z), duration);
		this.director.queueAction(action);
		this.director.updateCamera(0.0f);
	}
	
	public void setFocusAction(String nodeName, float x, float y, float z){
		
		Node node = new Node( nodeName );
		node.setLocalTranslation(new Vector3f(x, y, z));
		
		SetFocusAction action = new SetFocusAction(this.director, node);
		this.director.queueAction(action);
		
		while( ! action.isFinished() ) {
			this.director.updateCamera(0.0f);
		}
	}
	
	public String getFocusedNode() {
		return director.getFocusedObject().getName();
	}
	
	public String getCamPosition(){
		
		return "[" + this.director.getCamera().getLocalTranslation().x +
			   "," + this.director.getCamera().getLocalTranslation().y +
			   "," + this.director.getCamera().getLocalTranslation().z + "]";
	}
	
	public String getCamRotation(){
		
		return "[" + this.director.getCamera().getLocalRotation().x +
		   "," + this.director.getCamera().getLocalRotation().y +
		   "," + this.director.getCamera().getLocalRotation().z +
		   "," + this.director.getCamera().getLocalRotation().w + "]";
	}
}
